<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

//应用上下文:document
//var _documentContext = "<%=request.getContextPath() %>";

//各业务模块，必须定义的变量（框架issue.js文件中需用到，不要修改变量名）
var _title;	//业务标题
var _issueId; //业务主键
var _doSurplusWork = _documentContext + "/docDispatch/doSurplusWork";//（流程启动成功后业务数据的相关操作）业务模块自己定义的业务处理方法，以供框架在提交完成后，进行触发

//各业务模块，其他变量定义
var zsDate=new Array();//主送数据
var cbDate=new Array();//抄报数据
var csDate=new Array();//抄送数据 
var fsDate=new Array();//分送数据
var hqDate=new Array();//会商数据
var flagArray=new Array();//标识修改了以上哪些数组里面数据

//补发数据
var zsDateR=new Array();//主送数据
var cbDateR=new Array();//抄报数据
var csDateR=new Array();//抄送数据
var fsDateR=new Array();//分送数据

//var officeData=new Array();//正文数据

var oldFormDate;//表单数据

var oldFormId="<c:out value='${docIssue.formId}'/>";
var isNumber = "<c:out value='${isNumber}'/>";

var isSeal = "<c:out value='${isSeal}'/>";//是否已经签章

var signDate = "<c:out value='${signDate}'/>";//会签完成时限

/**
 * 业务数据初始化
 */
$(function(){
	
	$("#dialogDivNotic").dialog({
		title:"会议通知",//标题
		width: 980,//宽度
	    height: 480,//高度
	    top: 30,
	    closed: true,//初始关闭
	    cache: false,//缓存
	    modal: true,
	    onClose: function() {
			 $("#dialogIframeNotice").attr("src","");
			} 
	});
	
	
	//文书分类隐藏
	
	//禁止后退键 作用于Firefox、Opera
	 document.onkeypress=banBackSpace;
	 //禁止后退键 作用于IE、Chrome
	 document.onkeydown=banBackSpace;

	_issueId=$("#docId").val();//流程id,查询已有附件条件

	contentControlId="docIssueTable";//正文部分容器id,用于浮动菜单显示隐藏正文要素
	
	_officialId="<c:out value='${synOfficial.officialId}' />";//正文id初始化,用于判断是否有正文
	_officialVersionType="<c:out value='${synOfficial.officialVersionType}' />";//正文状态：套红，取消套红，签章，取消签章
	
	_printFormUrl = _documentContext+"/docDispatch/show/"+_issueId;//浮动菜单，打印处理单
	mergeDocObjUrl="<c:url value='/docDispatch/getMergeDocObj' />";//套红获取数据url
	
	addValid();
	
	oldFormDate=$.trim($('#docIssueForm').serialize());
	
	inintData();
	
	if($.type(inintCorrelationIssuePage) == "function"){
		inintCorrelationIssuePage();
		var isNewFlag=_workEffortId=="isNew";
		var todoFlag=_issueType=="todo" && (isNewFlag || actionPermissionJson.EditForm=="true");
		if(todoFlag){
			$(".correlationBtn").show();
		}else{
			$(".correlationBtn").hide();
		}
	}
	
	if('yes'==isNumber){
		$("#isArchiveId").combobox({
			readonly:true
		});
		 $('#isArchiveId').combobox('setValue', '1');
	}else{
		$("#isArchiveId").combobox({
			readonly:false
		});
		$('#isArchiveId').combobox('setValue', '0');
		
	}
	if(null!=signDate && ''!=signDate){
		$("#signDateShow").show();
	}else{
		$("#signDateShow").hide();
	}
});


//编辑会议通知按钮触发
$("#editMeetingNoticeBtn").click(function(){
	var docId = $("#docId").val();
	//alert(docId);
	var type = "dispatch";
	var yesNo="";
		$.ajax({
			 type: "POST",
			 url: "<c:url value='/docDispatch/ThereAreMeetingNoticeObject' />",
			 data: {docId:docId},
			 dataType: "json",
			 success:function(msg){
				 if(msg.state == "500"){
					 $("#dialogIframeNotice").attr("src",_affairsContext+"/affMeetingNotice/editMeetingNotice?docId="+docId+"&type="+type);
					 $('#dialogDivNotic').dialog('open');
					 yesNo = "1";
				 }else{
					 $.messager.alert('提示','还未添加会议通知！');
					 //yesNo = "0";
				 }
			 }
		});
		//alert(yesNo);
	/*if(yesNo == "1"){
		$("#dialogIframeWorkOrder").attr("src",_affairsContext+"/affMeetingNotice/editMeetingNotice?docId="+docId);
		$('#dialogDivWorkOrder').dialog('open');
	}else if(yesNo == "0"){
		$.messager.alert('提示','还未添加会议通知！');
	}else{
		return ;
	}*/
	
	
	
});


function inintData(){
	//console.log(actionPermissionJson.IsSignatory)
	//赋值
	if(actionPermissionJson.DraftDeptLeader=="true"){//部门领导
		$("#draftOrgLeader").textbox("setValue","<c:out value='${personName}' />");
		$("#draftOrgLeaderCode").val("<c:out value='${personId}' />");
	}
	
	if(actionPermissionJson.OfficeSecretary=="true"){//核稿人
		$("#reviewer").textbox("setValue","<c:out value='${personName}' />");
		$("#reviewerCode").val("<c:out value='${personId}' />");
		$("#draftAuditTime").val(dataFormatStr(new Date(),"yyyy-MM-dd hh:mm:ss"));
	}
	
	if(actionPermissionJson.IsSignatory=="true"){//签发人
		//console.log(dataFormatStr(new Date(),"yyyy-MM-dd hh:mm:ss"))
		$("#signatory").textbox("setValue","<c:out value='${personName}' />");
		$("#signatoryCode").val("setValue","<c:out value='${personId}' />");
		$("#signatoryTime").val(dataFormatStr(new Date(),"yyyy-MM-dd hh:mm:ss"));
		$("#expeireTime").textbox("setValue",dataFormatStr(new Date(),"yyyy-MM-dd"));
	}
	
	if(actionPermissionJson.MergeDoc=="true"){//印制人：套红时候获取
		$("#printer").textbox("setValue","<c:out value='${personName}' />");
		$("#printerCode").val("<c:out value='${personId}' />");
	}
	
	if(actionPermissionJson.OfficeProcessing=="true"){//是否经过办公室审核，经过办公室审核后才能提交领导
		var submittedToLeaderNo=Number($("#submittedToLeader").val());
		if($("#submittedToLeader").val()=="" || submittedToLeaderNo<2){
			$("#submittedToLeader").val("1");
		}else if(submittedToLeaderNo==2){
			$("#submittedToLeader").val("3");
		}
	}
	
	if(actionPermissionJson.GroupOfficeProcessing=="true"){//是否经过集团办公室审核，经过办公室审核后才能提交领导
		var submittedToLeaderNo=Number($("#submittedToLeader").val());
		if($("#submittedToLeader").val()=="" || submittedToLeaderNo<1){
			$("#submittedToLeader").val("2");
		}else if(submittedToLeaderNo<3){
			$("#submittedToLeader").val("3");
		}
	}
	
	//赋值end
}

function test(){
	$.ajax({//ajax保存表单基本信息
		   type: "POST",
		   url: _synergyContext+"/basic/flowItem/test",
		   dataType: "json",
		   async:false,
		   success: function(msg){
		     
		   }
		});	
}
/**
 * 框架页面调用的保存方法
 */
function _saveOAdata(){
	
	if(!(new RegExp("DispatchFlow").test($("#processId").val()))){//如果不是发文流程，直接返回
		_title=$("#docName").val();
		return 0;
	}
	if(!checkPageItems()){//页面验证不通过
		return 1;
	}
	

	var status = submitOAdata();
	if(status != 100)
	{
		return 2;
	}
	
	return 0;//0:保存成功，1：验证未通过，2：数据保存错误
}

/**
 * 验证
 */

function checkPageItems(){
	var isMeeting = $("input[type='radio'][name='isMeeting']:checked").val();
	var docId = $("#docId").val();
	//alert(docId);
	//alert(isMeeting);
	if(isMeeting == "1"){
		$.ajax({
			 type: "POST",
			 url: "<c:url value='/docDispatch/ThereAreMeetingNoticeObject' />",
			 data: {docId:docId},
			 dataType: "json",
			 success:function(msg){
				 if(msg.state == "200"){
					 $("#dialogIframeNotice").attr("src",_affairsContext+"/affMeetingNotice/addMeetingNotice?docId="+docId);
					 $('#dialogDivNotic').dialog('open');
					 return true;
				 }else{
					 return false;
				 }
			 }
		});
	}
	
	if($("#docIssueForm").form('validate')){
		if(actionPermissionJson.DirNumber=="true" && $("#displayNumber").textbox("getValue")==""){
			//通过表单ID 去判断是否勾选了编号，如果勾选了则提示先编号，未勾选直接提交
			if('no'==isNumber){
				return true;
			}else{
				$.messager.alert("提示",'该文件还未编号，请先编号。');
				return false;
			}
		}
		return true;
	}
	
	
	
	return false;
}


/**
 * 保存业务数据
 * 返回值100:正常、200:数据保存失败、300:正文及附件保存失败、400:附件上传失败
*/
function submitOAdata(){
	var submitState=0;
	
	var newFormDate=$.trim($('#docIssueForm').serialize());
	var isArchiveIdTemp = $("#isArchiveId").combobox("getValue");
	//debugger
	
	

	if(oldFormDate==newFormDate){
		submitState=100;
	}else{
		$.ajax({//ajax保存表单基本信息
			   type: "POST",
			   url: "<c:url value='/docDispatch/save' />",
			   data: newFormDate,
			   dataType: "json",
			   async:false,
			   success: function(msg){
			     if(msg.state=="200"){
			    	 _issueId=msg.docIssue.docId;
			    	 $("#docId").val(_issueId);
			    	 _formId=$("#formId").combobox("getValue");
			    	 //_title=$("#docName").val();
			    	 oldFormDate=newFormDate;
			    	 submitState=100;
			    	 $("#saveFlag").val("0");
			    	 var docId = msg.docIssue.docId;
			    	 //alert(msg.docIssue.isPolicy);
			    	 //if(msg.docIssue.isPolicy == "1"){
			    		 //$("#dialogIframe").attr("src","<c:url value='/schedule/show' />?judge="+judge+"&id="+$("input[name='id']:checked").val());
			    		 //$("#dialogIframe").attr("src","<c:url value='/docDispatch/meetingNotice' />?docId="+docId);
			    		 ///affMeetingNotice/addMeetingNotice
			    		 //$('#dialogDiv').dialog('open');
			     }else{
			    	 submitState=500;
			     }
			   }
			});	
	}
	_title=$("#docName").val();
	if(submitState==100){//判断表单是否保存成功
		if(fileUploadSaveFileFt(_issueId,"0","0","AS","")){//保存附件
			if(fileUploadLawSaveFileFt(_issueId,"0","0","LS","")){//保存附件
	   		if(submitTarget(_issueId)){//保存抄送、抄报、主送、分送数据
	   			 if(bindOffice()){//保存正文,调用前需确保_issueId有值，是否需要_officialFlag
	   					submitState=100;
	   				}else{
	   					submitState=500;
	   			}
	   		 }else{
	   			 submitState=500;
	   		 }
	   		 
		}else{
	   		 submitState=500;
	   	 }
	   	 }else{
	   		 submitState=500;
	   	 }
	}
	return submitState;
}

//初始化并且绑定验证
function addValid(){
	var isNewFlag=_workEffortId=="isNew";
	var todoFlag=_issueType=="todo" && new RegExp("DispatchFlow").test(_processId) && (isNewFlag || actionPermissionJson.EditForm=="true");
	
	if(_issueType=="done"){
		$('#receiveStatus').attr("style","display:inline");
	}
	
	//附件start
	var controlId="fileUpload";//自定义控件名前缀
	var delFlag=(_workEffortId=="isNew" || _issueType=="todo" && new RegExp("DispatchFlow").test(_processId) && actionPermissionJson.ModifyAttach=="true")?"1":"0";//显示删除按钮：0，不显示；1，显示
	var addFlag=(_workEffortId=="isNew" || _issueType=="todo" && new RegExp("DispatchFlow").test(_processId) && actionPermissionJson.ModifyAttach=="true")?"1":"0";//添加按钮可用：0，不可用；1，可用
	var showControlFlag=(_workEffortId=="isNew" ||_issueType=="todo" && new RegExp("DispatchFlow").test(_processId) && actionPermissionJson.ModifyAttach=="true")?"1":"0";//显示file控件和上传按钮：0，不显示；1，显示
	//var docType="";//流程状态：为done时候控制file控件和上传按钮不显示----issue.js已有
	var attachNo="0";//查询已有附件条件
	var attachVersion="0";//查询已有附件条件
	var attachType="AS";//查询已有附件条件
	//设置附件在word控件中打开后是否只读，默认只读true，如果为false，文件可编辑保存
	var fileReadOnly=!(_workEffortId=="isNew" || _issueType=="todo" && actionPermissionJson.ModifyAttach=="true");
	
	$("#fileDiv").panel({
	    href:_synergyContext+'/basic/synAttach/gotoSynAttachPage?docId='
	    	+_issueId+'&controlId='+controlId+'&delFlag='+delFlag+'&addFlag='+addFlag
	    	+'&showControlFlag='+showControlFlag+'&docType='+_issueType
	    	+"&attachNo="+attachNo+"&attachVersion="+attachVersion
			   +"&attachType="+attachType+"&fileReadOnly="+fileReadOnly,
	    border:false,//不显示边框
	    cache:false//不从缓存加载面板
	});
    //附件end
	//法律意见书start
	controlId="fileUploadLaw";
	delFlag=_issueType=="todo" && new RegExp("DispatchCounterSign").test(_processId) && $("#processId").val()=="DOC_DispatchFlow" && _signDeptId=="<c:out value='${JJOrgId}' />" && "<c:out value='${JJOrgId}' />"!=""?"1":"0" ;//当前处于子流程中，并且当前流程对应部门为建管纪检部
	addFlag=delFlag;
	showControlFlag=delFlag;
	attachType="LS";
	var fileReadOnly=delFlag!="1";
	
	$("#fileDivLs").panel({
	    href:_synergyContext+'/basic/synAttach/gotoSynAttachPage?docId='
	    	+_issueId+'&controlId='+controlId+'&delFlag='+delFlag+'&addFlag='+addFlag
	    	+'&showControlFlag='+showControlFlag+'&docType='+_issueType
	    	+"&attachNo="+attachNo+"&attachVersion="+attachVersion
			   +"&attachType="+attachType+"&fileReadOnly="+fileReadOnly,
	    border:false,//不显示边框
	    cache:false,//不从缓存加载面板
	    onLoad:function(){
	    	if(fileUploadLawGetAllFileNum()>0 || $("#processId").val()=="DOC_DispatchFlow" && _issueType=="todo" && _signDeptId=="<c:out value='${JJOrgId}' />" && "<c:out value='${JJOrgId}' />"!=""){
	    		$("#lawFileTr").show();
	    	}else{
	    		$("#lawFileTr").hide();
	    	}
	    }
	});
	
	//法律意见书end
	
	//发文抬头
	
	$("#formId").combobox({ 
		editable:false, 
		disabled:!todoFlag,
		required: true,
		onSelect:function(record){
			if(oldFormId!=record.value){
				_formId = record.value;//给issue.js里的_formId 重新赋值，这样点击底稿编辑时能获取当前表单的套红模板
				$.ajax({
					   type: "POST",
					   url: _synergyContext+"/basic/flowItem/updateFlow",
					   data: "workEffortId="+_workEffortId+"&formId="+record.value,
					   async: false,
					   success: function(msg){
						  if(msg.state=="200"){
							  $("#formName").val(record.text);
							   $("#captionValue").text(record.text+"（"+$("#formId option[value='"+record.value+"']").attr("flowName")+"）");
							   oldFormId=record.value;  
							   _formId = record.value;
							   //_issueId = msg.issueId;
							   //$("#docId").val(msg.issueId);
							   
							   formChange ="yes";
							   var isNumberTemp = msg.isNumber;
							   if('yes'==isNumberTemp){
									 $("#isArchiveId").combobox({
											disabled:true
										});
									 $('#isArchiveId').combobox('setValue', '1');
								}else{
									$("#isArchiveId").combobox({
										disabled:false
									});
									$('#isArchiveId').combobox('setValue', '0');
								}
						  }else{
							  $("#formId").combobox("select",oldFormId);
							  $.messager.alert("提示",'选择发文抬头失败，请重新选择');
						  }
					   },
					   error:function(){
						   $("#formId").combobox("select",oldFormId);
						   $.messager.alert("提示",'选择发文抬头失败，请重新选择');
					   }
					});
			}else{
				$("#captionValue").text(record.text+"（"+$("#formId option[value='"+record.value+"']").attr("flowName")+"）");
				$("#formName").val(record.text);
			}
		}
	});
	
	
	if(todoFlag){
		$("#editManuscriptWordDiv").show();//编辑底稿
		$("#editWordDiv").hide();//编辑正文
	}

	//控制编辑正文、底稿
	if(new RegExp("DispatchFlow").test(_processId)){
		
		var officialFlag= _officialVersionType=="CD" || _officialVersionType=="SD" ;
		//var officialFlag= _officialVersionType=="CD" || _officialVersionType=="MD" || _officialVersionType=="SD" || _officialVersionType=="US";
		if(_issueType=="todo"){//待办
			if(officialFlag){//(原已套红或者签章)  修改为 已签章的才代表正文by zj
				if(actionPermissionJson.DocReadOnly == "true") {//编辑底稿
					$("#editManuscriptWordDiv").hide();//编辑底稿
					$("#viewManuscriptWordDiv").hide();//查看底稿
					$("#editWordDiv").hide();//编辑正文
					$("#viewWordDiv").show();//查看正文
				}else{
					$("#editManuscriptWordDiv").hide();//编辑底稿
					$("#viewManuscriptWordDiv").hide();//查看底稿
					$("#editWordDiv").show();//编辑正文
					$("#viewWordDiv").show();//查看正文
					
				}
			}else{
				if(actionPermissionJson.DocReadOnly == "true") {//编辑底稿
					$("#editManuscriptWordDiv").hide();//编辑底稿
					$("#viewManuscriptWordDiv").show();//查看底稿
					$("#editWordDiv").hide();//编辑正文
					$("#viewWordDiv").hide();//查看正文
				}else{
					$("#editManuscriptWordDiv").show();//编辑底稿
					$("#viewManuscriptWordDiv").show();//查看底稿
					$("#editWordDiv").hide();//编辑正文
					$("#viewWordDiv").hide();//查看正文
					
				}
			}
		}else{//已办
			if(officialFlag){
				$("#viewWordDiv").show();
				$("#viewManuscriptWordDiv").hide();
			}else{
				$("#viewWordDiv").hide();
				$("#viewManuscriptWordDiv").show();
			}
		}
	}else if(new RegExp("DispatchCounter").test(_processId)){
		var officialFlag= _officialVersionType=="CD" || _officialVersionType=="SD" ;
		//var officialFlag= _officialVersionType=="CD" || _officialVersionType=="MD" || _officialVersionType=="SD" || _officialVersionType=="US";
		if(_issueType=="todo"){//待办
			if(officialFlag){//(原已套红或者签章)  修改为 已签章的才代表正文by zj
				$("#editManuscriptWordDiv").hide();//编辑底稿
				$("#viewManuscriptWordDiv").hide();//查看底稿
				$("#editWordDiv").hide();//编辑正文
				$("#viewWordDiv").show();
			}else{
				$("#editManuscriptWordDiv").hide();//编辑底稿
				$("#viewManuscriptWordDiv").show();//查看底稿  by zj 在没签章前也能查看底稿
				$("#editWordDiv").hide();//编辑正文
				$("#viewWordDiv").hide();//编辑正文
			}
		}else{//已办
			if(officialFlag){
				$("#viewWordDiv").show();
				$("#viewManuscriptWordDiv").hide();
			}else{
				$("#viewWordDiv").hide();
				$("#viewManuscriptWordDiv").show();
			}
		}
	}
	
	
	//标题
	$("#docName").textbox({
	    required: true,
	    validType:'length[1,85]',
	    multiline:true,
	    editable:todoFlag
	});
	//紧急程度,密级
	$("#emergencyCode,#secretCode").combobox({
		editable:false,
		disabled:!todoFlag
	});
	//是否归档
	$("#isArchiveId").combobox({
		editable:false,
		//disabled:!(todoFlag && !isNewFlag)
		disabled:(!todoFlag || 'yes'==isNumber),
		onSelect:function(record){
			$("#isArchive").val(record.value);
		},
	});
	//发文日期，办结时限
	/*$("#sendTime,#expeireTime").datebox({
		editable:false,
		disabled:!todoFlag
	});*/
	

	//拟稿部门，拟稿人，拟稿部门领导，核稿人，拟稿时间
	$("#draftOrg,#drafter,#draftOrgLeader,#createTime,#signatory,#expeireTime").textbox({
		editable:false
	});
	$("#printer").textbox({
		editable:true
	});
	
	//正文按钮
	if(todoFlag){
		//if(isNewFlag){
		if(_officialId==""){
			$("#wordLink").html("新建正文");
		}else{
			$("#wordLink").html("编辑正文");
		}
	}else{
		$("#wordLink").html("查看正文");
	}
	
	
	
	/*//拟稿人电话
	$("#drafterTel").textbox({
		required: true,
	    editable:todoFlag
	});*/
	
	//是否通过会议讨论
	$("input[name='isMeetingDiscuss']").attr("disabled",!todoFlag);
	$("input[name='isMeeting']").attr("disabled",!todoFlag);
	$("#editMeetingNoticeBtn").attr("disabled",!todoFlag);
	//是否公开---------
	$("input[name='public']").attr("disabled",!todoFlag);
	//不公开理由
	$("#publicReason").textbox({
		multiline:true,
		validType:'length[0,85]',
	    editable:todoFlag,
	    required:true
	    
	});
	
	//是否公开
	/*$('#isPublic').combobox({
		editable:false, 
		onSelect:function(record){
			if(record.value=="0"){
				//0522 hcd增加是不予公开，必须填写不公开理由start
				$("#publicReason").textbox("enableValidation");
				//0522 hcd增加是不予公开，必须填写不公开理由end
				$("#publicReasonTR").show();
			}else{
				//0522 hcd增加是不予公开，必须填写不公开理由start
				$("#publicReason").textbox("disableValidation");
				//0522 hcd增加是不予公开，必须填写不公开理由end
				$("#publicReasonTR").hide();
				
			}
		},
		disabled:!todoFlag
	});*/
	
	//政策解读
	$("#policyDescription").textbox({
		multiline:true,
		validType:'length[0,85]',
		editable:todoFlag,
		required:true
		
	});
	
	//是否政策法规文件
	/*$("input[name='isPolicy']").click(function(){
		changePolicyDescriptionTR();
	}).attr("disabled",!todoFlag);
	changePolicyDescriptionTR();//初始化调用次，显示或者隐藏政策解读
*/	
	$("input[name='isPolicy'],input[name='isPublic']").attr("disabled",!todoFlag);
	
	//是否督办
	if(todoFlag && actionPermissionJson.IsSupervision=="true"){
		$("input[name='isSuperviseValue']").click(function(){$("#isSupervise").val($(this).val());});
	}/*else{
		$("input[name='isSuperviseValue']").attr("disabled",true);
	}*/
	
	//发送至国家局
	var _sendDocNation = actionPermissionJson.SendNationDoc == "true";
	if(todoFlag && _sendDocNation){
		$('#nationDoc').attr("style","display:inline");
	}else{
		$('#nationDoc').attr("style","display:none");
	}
	
	if($("#printNum").val()==""){
		$("#printNum").val("5");
	}
	//份数
	$("#printNum").numberbox({
		required: true,
	    min:1,
	    precision:0,
	    editable:todoFlag
	});
	
	//密级
	$('#draftOrgLeader').combobox({
		required: true,
		validType:"selectValueRequired",
		editable:false, 
		onSelect:function(record){
			/*$("#docCategoryName").val(record.value==""?"":record.text);*/
		},
		disabled:!todoFlag
	});
	//文种
	//$('#docCategoryId').combobox({
	//	//required: true,
	//	validType:"selectValueRequired",
	//	editable:false, 
	//	onSelect:function(record){
	//		$("#docCategoryName").val(record.value==""?"":record.text);
	//	},
	//	disabled:!todoFlag
	//});
	
	//归档分类
	$('#archiveCategoryId').combobox({
		editable:false, 
		onSelect:function(record){
			$("#archiveCategoryName").val(record.value==""?"":record.text);
		},
		disabled:!(todoFlag && !isNewFlag)
	});
	
	//正文页数
	$("#pageNum").numberbox({
	    min:1,
	    precision:0,
	    editable:todoFlag
	});
	
	;
	var targetConfirm=_issueType=="todo" && new RegExp("DispatchFlow").test(_processId)&&(actionPermissionJson.MainTargetConfirm=="true"||isNewFlag);
	/*if(todoFlag&&targetConfirm || _issueType!="todo"){
		$(".target").show();
	}else{
		$(".target").hide();
	}*/
	$("#inputZS").textbox({
		/*required: true,*/
		multiline:true,
		editable:targetConfirm&&$.trim($("#inputZS").text())!=""
	});
	$("#inputCS").textbox({
		multiline:true,
		editable:targetConfirm&&$.trim($("#inputCS").text())!=""
	});
	$("#divZS").dialog({
		title:"主送单位",//标题
		width: 835,//宽度
	    height: 400,//高度
	    closed: true,//初始关闭
	    cache: true,//缓存
	    modal: true,
	    href: '<c:url value="/synOrgExt/synExtDialogList" />?name=zs&type=MT&docId='+_issueId+"&editFlag="+targetConfirm,
	    buttons:[{
			text:'刷新',
			handler:function(){
				$("#divZS").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=zs&type=MT&docId='+_issueId+"&editFlag="+targetConfirm);
				zsDate.length=0;
			}
		},{
			text:'确定',
			handler:function(){
				var obj=zsAllData();
				if(obj.state){
					zsDate=obj.data;
					$("#inputZS").textbox("setValue",obj.title);
					$("#inputZS").textbox({
						editable:$.trim($("#inputZS").textbox("getValue"))!=""
					});
//					if(!$.isEmptyObject($("#inputZS").combobox("getValues"))){
//						/*var first=new Object();
//				    	first.targetCode="";
//				    	first.targetName=idsToStr($("#inputZS").combobox("getValues"));
//				    	first.targetType="MT";
//				    	zsDate.unshift(first);*/
//						setTargetDate("inputZS","MT",zsDate,true);
//					}

//					$("#inputZS").textbox('setValue', obj.title);
					if($.inArray("MT", flagArray)==-1){
						flagArray.push("MT");
					}
					
					$("#divZS").dialog("close");
				}
			}
		},{
			text:'关闭',
			handler:function(){$("#divZS").dialog("close");}
		}]
	});
	$("#imgZS").click(function(){$("#divZS").dialog("open").window("center");});
/*	$("#divCB").dialog({
		title:"抄报单位",//标题
		width: 800,//宽度
	    height: 400,//高度
	    closed: true,//初始关闭
	    cache: true,//缓存
	    modal: true,
	    href: '<c:url value="/synOrgExt/synExtDialogList" />?name=cb&type=RT&docId='+_issueId+"&editFlag="+(todoFlag&&targetConfirm),
	    buttons:[{
			text:'刷新',
			handler:function(){
				$("#divCB").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=cb&type=RT&docId='+_issueId+"&editFlag="+(todoFlag&&targetConfirm));
				cbDate.length=0;
			}
		},{
			text:'确定',
			handler:function(){
				var obj=cbAllData();
				if(obj.state){
					cbDate=obj.data;
					
//					if(!$.isEmptyObject($("#inputCB").combobox("getValues"))){
//						var first=new Object();
//				    	first.targetCode="";
//				    	first.targetName=idsToStr($("#inputCB").combobox("getValues"));
//				    	first.targetType="RT";
//				    	cbDate.unshift(first);
//						setTargetDate("inputCB","RT",cbDate,true);
//					}
					
//					$("#inputCB").textbox('setValue', obj.title);
					if($.inArray("RT", flagArray)==-1){
						flagArray.push("RT");
					}
					$("#divCB").dialog("close");
				}
			}
		},{
			text:'关闭',
			handler:function(){$("#divCB").dialog("close");}
		}]
	});
	$("#imgCB").click(function(){$("#divCB").dialog("open").window("center");});*/
	$("#divCS").dialog({
		title:"抄送单位",//标题
		width: 890,//宽度
	    height: 400,//高度
	    closed: true,//初始关闭
	    cache: true,//缓存
	    modal: true,
	    href: '<c:url value="/synOrgExt/synExtDialogList" />?name=cs&type=CT&docId='+_issueId+"&editFlag="+targetConfirm,
	    buttons:[{
			text:'刷新',
			handler:function(){
				$("#divCS").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=cs&type=CT&docId='+_issueId+"&editFlag="+targetConfirm);
				csDate.length=0;
			}
		},{
			text:'确定',
			handler:function(){
				var obj=csAllData();
				if(obj.state){
					csDate=obj.data;
					$("#inputCS").textbox("setValue",obj.title);
					$("#inputCS").textbox({
						editable:$.trim($("#inputCS").textbox("getValue"))!=""
					});
//					if(!$.isEmptyObject($("#inputCS").combobox("getValues"))){
//						/*var first=new Object();
//				    	first.targetCode="";
//				    	first.targetName=idsToStr($("#inputCS").combobox("getValues"));
//				    	first.targetType="CT";
//				    	csDate.unshift(first);*/
//						setTargetDate("inputCS","CT",csDate,true);
//					}
			    	
//					$("#inputCS").textbox('setValue', obj.title);
					if($.inArray("CT", flagArray)==-1){
						flagArray.push("CT");
					}
					$("#divCS").dialog("close");
				}
			}
		},{
			text:'关闭',
			handler:function(){$("#divCS").dialog("close");}
		}]
	});
	$("#imgCS").click(function(){$("#divCS").dialog("open").window("center");});
	/*$("#divFS").dialog({
		title:"分送单位",//标题
		width: 800,//宽度
	    height: 400,//高度
	    closed: true,//初始关闭
	    cache: true,//缓存
	    modal: true,
	    href: '<c:url value="/synOrgExt/synExtDialogList" />?name=fs&type=ST&docId='+_issueId+"&editFlag="+(todoFlag&&targetConfirm),
	    buttons:[{
			text:'刷新',
			handler:function(){
				$("#divFS").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=fs&type=ST&docId='+_issueId+"&editFlag="+(todoFlag&&targetConfirm));
				fsDate.length=0;
			}
		},{
			text:'确定',
			handler:function(){
				var obj=fsAllData();
				if(obj.state){
					fsDate=obj.data;

//					if(!$.isEmptyObject($("#inputFS").combobox("getValues"))){
//						var first=new Object();
//				    	first.targetCode="";
//				    	first.targetName=idsToStr($("#inputFS").combobox("getValues"));
//				    	first.targetType="ST";
//				    	fsDate.unshift(first);
//						setTargetDate("inputFS","ST",fsDate,true);
//					}
					
//					$("#inputFS").textbox('setValue', obj.title);
					if($.inArray("ST", flagArray)==-1){
						flagArray.push("ST");
					}
					$("#divFS").dialog("close");
				}
			}
		},{
			text:'关闭',
			handler:function(){$("#divFS").dialog("close");}
		}]
	});
	$("#imgFS").click(function(){$("#divFS").dialog("open").window("center");});*/
	/*$("#divHQ").dialog({
		title:"会签单位",//标题
		width: 800,//宽度
	    height: 400,//高度
	    closed: true,//初始关闭
	    cache: true,//缓存
	    modal: true,
	    href: '<c:url value="/synOrgExt/synExtDialogList" />?name=hq&type=CS&docId='+_issueId+"&editFlag="+todoFlag,
	    buttons:[{
			text:'确定',
			handler:function(){
				var obj=hqAllData();
				if(obj.state){
					hqDate=obj.data;
					$("#inputHQ").textbox('setValue', obj.title);
					$("#divHQ").dialog("close");
				}
			}
		},{
			text:'关闭',
			handler:function(){$("#divHQ").dialog("close");}
		}]
	});
	$("#imgHQ,#inputHQ").click(function(){$("#divHQ").dialog("open").window("center");});*/
	
	if(_issueType == "done" && actionPermissionJson.AddSend == "true"){//--------------------------补送初始化

		$("#divZSR").dialog({
			title:"补送：主送单位",//标题
			width: 800,//宽度
		    height: 400,//高度
		    closed: true,//初始关闭
		    cache: true,//缓存
		    modal: true,
		    href: '<c:url value="/synOrgExt/synExtDialogListR" />?name=zs&type=MT&docId='+_issueId,
		    buttons:[{
				text:'刷新',
				handler:function(){
					$("#divZSR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=zs&type=MT&docId='+_issueId);
					zsDateR.length=0;
				}
			},{
				text:'确定',
				handler:function(){
					var obj=zsAllDataR();
					if(obj.state){
						zsDateR=obj.data;
						if($.inArray("MT", flagArray)==-1){
							flagArray.push("MT");
						}
						$("#divZSR").dialog("close");
					}
				}
			},{
				text:'关闭',
				handler:function(){$("#divZSR").dialog("close");}
			}]
		});
		$("#imgZSR").click(function(){$("#divZSR").dialog("open").window("center");});
		/*$("#divCBR").dialog({
			title:"补送：抄报单位",//标题
			width: 800,//宽度
		    height: 400,//高度
		    closed: true,//初始关闭
		    cache: true,//缓存
		    modal: true,
		    href: '<c:url value="/synOrgExt/synExtDialogListR" />?name=cb&type=RT&docId='+_issueId,
		    buttons:[{
				text:'刷新',
				handler:function(){
					$("#divCBR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=cb&type=RT&docId='+_issueId);
					cbDateR.length=0;
				}
			},{
				text:'确定',
				handler:function(){
					var obj=cbAllDataR();
					if(obj.state){
						cbDateR=obj.data;
						if($.inArray("RT", flagArray)==-1){
							flagArray.push("RT");
						}
						$("#divCBR").dialog("close");
					}
				}
			},{
				text:'关闭',
				handler:function(){$("#divCBR").dialog("close");}
			}]
		});
		$("#imgCBR").click(function(){$("#divCBR").dialog("open").window("center");});*/
		$("#divCSR").dialog({
			title:"补送：抄送单位",//标题
			width: 890,//宽度
		    height: 400,//高度
		    closed: true,//初始关闭
		    cache: true,//缓存
		    modal: true,
		    href: '<c:url value="/synOrgExt/synExtDialogListR" />?name=cs&type=CT&docId='+_issueId,
		    buttons:[{
				text:'刷新',
				handler:function(){
					$("#divCSR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=cs&type=CT&docId='+_issueId);
					csDateR.length=0;
				}
			},{
				text:'确定',
				handler:function(){
					var obj=csAllDataR();
					if(obj.state){
						csDateR=obj.data;
						if($.inArray("CT", flagArray)==-1){
							flagArray.push("CT");
						}
						$("#divCSR").dialog("close");
					}
				}
			},{
				text:'关闭',
				handler:function(){$("#divCSR").dialog("close");}
			}]
		});
		$("#imgCSR").click(function(){$("#divCSR").dialog("open").window("center");});
		/*$("#divFSR").dialog({
			title:"补送：分送单位",//标题
			width: 800,//宽度
		    height: 400,//高度
		    closed: true,//初始关闭
		    cache: true,//缓存
		    modal: true,
		    href: '<c:url value="/synOrgExt/synExtDialogListR" />?name=fs&type=ST&docId='+_issueId,
		    buttons:[{
				text:'刷新',
				handler:function(){
					$("#divFSR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=fs&type=ST&docId='+_issueId);
					fsDateR.length=0;
				}
			},{
				text:'确定',
				handler:function(){
					var obj=fsAllDataR();
					if(obj.state){
						fsDateR=obj.data;
						if($.inArray("ST", flagArray)==-1){
							flagArray.push("ST");
						}
						$("#divFSR").dialog("close");
					}
				}
			},{
				text:'关闭',
				handler:function(){$("#divFSR").dialog("close");}
			}]
		});
		$("#imgFSR").click(function(){$("#divFSR").dialog("open").window("center");});*/
	
	}else{
		$(".targetR").hide();
	}
	$('#printForm').show();
}
function submitTarget(docId){
	var obj=new Array();
	
	setTargetDate("inputZS","MT",zsDate,true);
	if(zsDate.length>0){
		$.merge(obj, zsDate );
	}
	

	setTargetDate("inputCS","CT",csDate,true);
	if(csDate.length>0){
		$.merge(obj, csDate );
	} 
	
	var paramObj = {
			"targets":obj
	};
	
	var flag=false;
	var delFlags="";
	$.each( flagArray, function(i, n){
		delFlags+=(delFlags==""?"":",")+n;
		});
	
	if(obj.length==0 && delFlags==""){
		return true;
	}
	
	$.ajax({
		   type: "POST",
		   url: "<c:url value='/docTarget/save'/>",
		   data: "dataStr="+encodeURIComponent(encodeURIComponent(JSON.stringify(paramObj)))+"&docId="+docId+"&delFlags="+delFlags,
		   dataType: "json",
		   async:false,
		   success: function(msg){
			   flag=msg.state=="200";
			   zsDate.length=0;
			   cbDate.length=0;
			   csDate.length=0;
			   fsDate.length=0;
			   flagArray.length=0;
		   }
		});
	return flag;
}

function changePolicyDescriptionTR(){
	if($("input[name='isPolicy']:checked").val()=="1"){
		//0522 hcd增加是政策法规，政策解读必填 start
		$("#policyDescription").textbox("enableValidation");
		//0522 hcd增加是政策法规，政策解读必填 end
		$("#policyDescriptionTR").show();
		$("#policyDescription").css("width","85%");
	}else{
		//0522 hcd增加是政策法规，政策解读必填 start
		$("#policyDescription").textbox("disableValidation");
		//0522 hcd增加是政策法规，政策解读必填 end
		$("#policyDescriptionTR").hide();
	}
}

/**
 * 浮动工具栏：接收情况
 * 
 * @returns
 */
function _receiveStatus(){
	var url = "<c:url value='/receive/receiveStatusList/' />"+_issueId+"?handleFlag="+(actionPermissionJson.ReceiveStatus == "true"?"1":"0");
	var winFeatures = "height=500px,width=1000px,top=50px,left=200px,toolbar=no,menubar=no,resizable=no,location=no,status=no,scrollbars=yes";
	window.open(url,'_blank',winFeatures);
}

function beforeChooseActivityId() {
	var returnObj=new Object();
	returnObj.state=true;
	returnObj.msg=new Array();
	if(_officialId==""){
		$.messager.alert("提示",'请编辑底稿');
		if(returnObj.state){
			returnObj.state=false;
		}
		return returnObj;
	}
	
	
	/*if(actionPermissionJson.DirNumber=="true" && $("#displayNumber").textbox("getValue")==""){
		returnObj.msg.push('您还未选择发文号，是否继续提交？');
		if(returnObj.state){
			returnObj.state=false;
		}
	}*/
	
	if(actionPermissionJson.ShowDeliverTip=="true"){
		returnObj.msg.push('请确认该文件是否需要邮送，如需要，点击“确定”；如不需要，点击“取消”。');
		if(returnObj.state){
			returnObj.state=false;
		}
	}
	
	if(actionPermissionJson.MergeDoc=="true" && _officialVersionType!="MD"){
		returnObj.msg.push('您还未进行套红操作，是否继续提交？');
		if(returnObj.state){
			returnObj.state=false;
		}
	}
	
	//如果是编号盖章节点，则在提交时判断是否已经盖章
    if(actionPermissionJson.SealDoc == "true" && _officialVersionType!="SD"){
    	returnObj.msg.push('您还未进行签章操作，是否继续提交？');
		if(returnObj.state){
			returnObj.state=false;
		}
    }

	return returnObj;
}

function idsToStr(arrayObj){
	var ids="";
	$.each( arrayObj, function(i, n){
		ids+=(ids==""?"":"|")+n;
		});
	return ids;
}
function setTargetDate(controlName,type,arrayObj,flag){
	var first=new Object();
	first.targetCode="";
//	first.targetName=$("#"+controlName).combobox("getValues").join('，');
	first.targetName=$("#"+controlName).textbox("getValue");
	first.targetType=type;
	
	
/*	var second=new Object();
	second.targetCode="";
	second.targetName=$("#"+controlName).combobox("getText");
	second.targetType=type;
	second.targetDiv="#tt";*/
	
	if(flag){
//		arrayObj.unshift(second);
		arrayObj.unshift(first);
	}else{
		arrayObj[0]=first;
//		arrayObj[1]=second;
	}
}
function getComboboxValue(controlId){
	return $("#"+controlId).combobox('getText');
}

/*控件兼容后本段已经失效，tipDiv.js中默认设置了10M限制，如需整体修改，请在tipDiv.js中修改；如果只改自己业务中限制，请在自己业务的js里面修改limitObj.num、limitObj.str
 * 
 * function getOfficeLimit(){
	var limitObj=new Object();
	if(RegExp(/国家/).test($("#inputZS").combobox('getText'))){
		limitObj.num=3145728;
		limitObj.str="3M";
	}else{
		limitObj.num=10485760;
		limitObj.str="10M";
	}
	return limitObj;
}*/

/**
 * 下载正文
 * @returns
 */
function downloadOfficeFile(){
	window.location.href=_synergyContext+'/basic/office/downLoadFile?docId='+$("#docId").val()+"&officeName="+encodeURIComponent(encodeURIComponent($("#docName").textbox("getValue").replace(/\n/g,' ')));
}

/**
 * 批量下载文件（正文 + 附件）
 * @returns
 */
function batchDownLoadFile(){
	window.location.href=_synergyContext+'/basic/office/batchDownLoadFile?docId='+$("#docId").val()+"&officeName="+encodeURIComponent(encodeURIComponent($("#docName").textbox("getValue").replace(/\n/g,' ')));
}

/**
 * 发文补发
 * @returns
 */
function _addSend(){
	var obj=new Array();
	var zsStrR="";
	var csStrR="";
	var cbStrR="";
	var fsStrR="";
	if(zsDateR.length>0){
		$.merge(obj, zsDateR );
		$.each( zsDateR, function(i, n){
			zsStrR+=(zsStrR==""?"":",")+n.targetName;
			});
	}
	
	if(cbDateR.length>0){
		$.merge(obj, cbDateR );
		$.each( cbDateR, function(i, n){
			cbStrR+=(cbStrR==""?"":",")+n.targetName;
			});
	} 
	
	if(csDateR.length>0){
		$.merge(obj, csDateR );
		$.each( csDateR, function(i, n){
			csStrR+=(csStrR==""?"":",")+n.targetName;
			});
	} 
	
	if(fsDateR.length>0){
		$.merge(obj, fsDateR );
		$.each( fsDateR, function(i, n){
			fsStrR+=(fsStrR==""?"":",")+n.targetName;
			});
	} 
	if(obj.length==0){
		$.messager.alert("提示",'您未选择任何邮送单位、部门 ，请选择后再补发');
		return;
	}
	
	$.messager.confirm('提示','请确认补发邮送信息：<br/><br/><br/>主送：<br/><span class="spaceSpan"></span>'+zsStrR+'<br/><br/>抄送：<br/><span class="spaceSpan"></span>'+csStrR,function(r){
		if(r){
			var paramObj = {
					"targets":obj
			};
			
			$.ajax({
				   type: "POST",
//				   url: "<c:url value='/docTarget/add'/>",
				   url: "<c:url value='/docTarget/addNew'/>",
				   data: "dataStr="+encodeURIComponent(encodeURIComponent(JSON.stringify(paramObj)))+"&docId="+_issueId+"&workEffortId="+_workEffortId+"&formId="+_formId+"&workflowActivityId="+_activityId,
				   dataType: "json",
				   async:false,
				   success: function(msg){
					   if(msg.state=="200"){
						  
						   if(zsDateR.length>0){
							   zsDateR.length=0;
							   $("#divZS").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=zs&type=MT&docId='+_issueId+"&editFlag=false");
							   $("#divZSR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=zs&type=MT&docId='+_issueId);
							  
							   $("#inputZS").textbox("setValue",msg.inputZS);
						   }
						   
						   if(cbDateR.length>0){
							   cbDateR.length=0;
							   $("#divCB").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=cb&type=RT&docId='+_issueId+"&editFlag=false");
							   $("#divCBR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=cb&type=RT&docId='+_issueId);
							  
							   $("#inputCB").textbox("setValue",msg.inputCB);
						   }
						  
						   if(csDateR.length>0){
							   csDateR.length=0;
							   $("#divCS").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=cs&type=CT&docId='+_issueId+"&editFlag=false");
							   $("#divCSR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=cs&type=CT&docId='+_issueId);
							  
							   $("#inputCS").textbox("setValue",msg.inputCS);
						   }
						  
						   if(fsDateR.length>0){
							   fsDateR.length=0;
							   $("#divFS").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogList" />?name=fs&type=ST&docId='+_issueId+"&editFlag=false");
							   $("#divFSR").dialog("refresh",'<c:url value="/synOrgExt/synExtDialogListR" />?name=fs&type=ST&docId='+_issueId); 
							   
							   $("#inputFS").textbox("setValue",msg.inputFS);
						   }
						 
//						   $.messager.confirm('提示',"操作成功,是否更新正文？",function(r){
//								if(r){
//									 _openWordAfterAddSend();
//								}
//								}); 
						  
					   }else{
						   $.messager.alert("提示",'操作失败');
					   }
				   }
				});
		}
	});
}

/**
 * 发送文件至国家局（解决目前文件到达国家局MQ前置机上时，由于默认设置成已签章，
 * 所以在前置机上面进行无法修改正文；而实际上文件可能还需要主送给其他单位）
 * @returns
 */
function _sendDocToNation(){
	$.ajax({
		  url: "<c:url value='/docDispatch/sendDocToNation' />",
		  cache: false,
		  async: false,
		  data: "docId="+_issueId,
		  success: function(msg){
		    
		  }
	});
}

function closeDialogDivNotic(){
	$("#dialogDivNotic").dialog('close');
}